<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增产品')"/>
    <th:block th:include="include :: ckeditor-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-product-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">商品名称：</label>
            <div class="col-sm-8">
                <input name="productName" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">商品详情：</label>
            <div class="col-sm-8">
                <textarea id="editor1" name="productDetails"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">父类id：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input id="treeId" name="classId" type="hidden" th:value="${bProductClass?.id}"/>
                    <input class="form-control" type="text" onclick="selectBusinessclassTree()" id="treeName"
                           readonly="true" th:value="${bProductClass?.name}" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: ckeditor-js"/>
<script th:inline="javascript">
    var editor;
    var prefix = ctx + "business/product"

    $("#form-product-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            editor.updateSourceElement();
            $.operate.save(prefix + "/add", $('#form-product-add').serialize());
        }
    }

    /*商品分类-新增-选择父部门树*/
    function selectBusinessclassTree() {
        var options = {
            title: '商品分类选择',
            width: "380",
            url: ctx + "business/businessclass/selectBusinessclassTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }

    ClassicEditor
        .create(document.querySelector('#editor1'), {
            language: "zh-cn",
            ckfinder: {
                uploadUrl: ctx + "businessfile/file/addfile",
            }
        })
        .then(newEditor => {
            editor = newEditor;
        })
        .catch(error => {
            console.error(error);
        });
</script>
</body>
</html>
